package com.authine.cloudpivot.ext.applicationservice;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.alibaba.cola.dto.RequestContext;
import com.alibaba.cola.dto.SingleResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.authine.cloudpivot.ext.applicationservice.base.ApplicationBaseService;
import com.authine.cloudpivot.ext.constants.ModelConst;
import com.authine.cloudpivot.ext.dto.OrderTraceDto;
import com.authine.cloudpivot.ext.dto.OrderVendorDto;
import com.authine.cloudpivot.ext.dto.OrderVendorGoodsDto;
import com.authine.cloudpivot.ext.dto.TraderSaveOrUpdateBo;
import com.authine.cloudpivot.ext.dto.api.AgreeRefundVO;
import com.authine.cloudpivot.ext.enums.report.ReportType;
import com.authine.cloudpivot.ext.service.OrderService;
import com.authine.cloudpivot.ext.service.TransferOrderService;
import com.authine.cloudpivot.ext.service.impl.OrderServiceImpl;
import com.authine.cloudpivot.ext.service.impl.TransferOrderServiceImpl;
import com.authine.cloudpivot.ext.utils.BoServiceUtils;
import com.authine.cloudpivot.ext.utils.JdbcTemplateUtils;
import com.authine.cloudpivot.ext.utils.StringUtils;
import com.authine.cloudpivot.ext.utils.Utils;
import com.authine.cloudpivot.ext.utils.system.ReportUtils;
import com.authine.common.json.JsonUtils;
import com.authine.mvp.app.launcher.domain.utills.ApplicationContextUtils;
import com.authine.mvp.app.launcher.dto.bo.response.BO;
import com.authine.mvp.app.launcher.dto.bo.response.BOList;
import com.authine.mvp.app.launcher.rpc.SaveOrUpdateBO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import java.util.*;
import java.util.stream.Collectors;

import static com.authine.hermes.app.launcher.service.ApplicationServiceFoundation.CUSTOM_SERVICE;

/**
 * @ClassName VendorDetailService
 * @Description: 供应商订单详情自定义服务
 * @Author cjj
 * @Date 2021/4/20
 * @Version V1.0
 **/
@Path("VendorDetailService")
@Slf4j
public class VendorDetailService extends ApplicationBaseService {
    private OrderService orderService = new OrderServiceImpl();
    private TransferOrderService transferOrderService = new TransferOrderServiceImpl();
    private NamedParameterJdbcTemplate jdbcTemplate = ApplicationContextUtils.getBean(NamedParameterJdbcTemplate.class);

    /**
     * 供应商订单详情页
     *
     * @param dto
     * @return
     */
    @Path("vendorDetail")
    @POST
    @Operation(summary = "供应商订单详情页", tags = CUSTOM_SERVICE, description = "id、pageIndex、pageSize必填")
    public SingleResponse<Map> vendorDetail(@Parameter OrderVendorDto dto) {
        log.info("------------------------供应商订单详情页vendorDetail Param：{}------------------------", JSONObject.toJSONString(dto));
        if (StringUtils.isBlank(dto.getId())) {
            return SingleResponse.buildFailure("-1", "供应商订单ID必填");
        }
        //供应商订单
        Map<String, Object> orderVendor = JdbcTemplateUtils.builder(ModelConst.T_ORDER_VENDOR).selectField("*")
                .eq("id", dto.getId()).queryForMap();
        if (CollectionUtils.isEmpty(orderVendor)) {
            return SingleResponse.buildFailure("-1", "供应商订单不存在");
        }
        Map<String, Object> orderCustomer = JdbcTemplateUtils.builder(ModelConst.T_ORDER_CUSTOMER).selectField("*")
                .eq("id", orderVendor.get("order_customer_id")).queryForMap();
        orderVendor.put("receiver", orderCustomer.get("receiver"));
        orderVendor.put("phone", orderCustomer.get("phone"));
        orderVendor.put("postal", orderCustomer.get("postal"));
        orderVendor.put("actual_order", orderCustomer.get("actual_order"));
        List<Map<String, Object>> orderVendorGoods = JdbcTemplateUtils.builder(ModelConst.T_ORDER_VENDOR_GOODS).selectField("*")
                .eq("order_vendor_id", dto.getId()).queryForList();
        for (Map<String, Object> orderVendorGood : orderVendorGoods) {
            List<Map<String, Object>> orderGoodsReturns = JdbcTemplateUtils.builder(ModelConst.T_ORDER_GOODS_RETURNS).selectField("*")
                    .eq("order_vendor_goods_id", orderVendorGood.get("id")).desc("createdTime").queryForList();
            if (!CollectionUtils.isEmpty(orderGoodsReturns)) {
                orderVendorGood.put("order_goods_returns_status", orderGoodsReturns.get(0).get("order_goods_returns_status"));
                orderVendorGood.put("is_to_pm", Utils.parseObjToBool(orderGoodsReturns.get(0).get("is_to_pm")));
            }
            orderVendorGood.put("order_vendor_status", orderVendor.get("order_vendor_status"));
            orderVendorGood.put("refunded_num", this.getRefundedNum(null, (String) orderVendorGood.get("id")));
            orderVendorGood.put("deliverable_num", this.getDeliverableNum((String) orderVendorGood.get("id")));
            //补充澄清,取冗余字段
//            Map<String, Object> extendsAttr = Objects.isNull(orderVendorGood.get("extends_attr")) ? null : JSON.parseObject((String) orderVendorGood.get("extends_attr"), HashMap.class);
//            orderVendorGood.put("clarify_tips", CollectionUtils.isEmpty(extendsAttr) ? null : extendsAttr.get("clarifyTips"));
            //商品
            orderVendorGood.put("full_name", orderVendorGood.get("brand") + " " + orderVendorGood.get("name") + " " + orderVendorGood.get("model") + " " + orderVendorGood.get("spec"));
            //报价备注,取冗余字段
//            Map<String, Object> quotationGoods = getQuotationGoodsByGoodsId((String) orderVendorGood.get("id"));
//            orderVendorGood.put("description", CollectionUtils.isEmpty(quotationGoods) ? null : quotationGoods.get("description"));
//            //标记信息,取冗余字段
//            orderVendorGood.put("tags", CollectionUtils.isEmpty(quotationGoods) ? null : quotationGoods.get("remark_message"));
            List<Map<String, Object>> orderGoodsRelationList = JdbcTemplateUtils.builder(ModelConst.T_ORDER_GOODS_RELATION).selectField("*").eq("id", orderVendorGood.get("relation_id")).queryForList();
            if (!CollectionUtils.isEmpty(orderGoodsRelationList)) {
                //送货要求
                orderVendorGood.put("extends_attr", orderGoodsRelationList.get(0).get("delivery_requirements"));
            }
        }
        log.info("------------------------供应商订单详情页vendorDetail Result：{}------------------------", JSONObject.toJSONString(orderVendor));
        orderVendor.put("children", orderVendorGoods);
        return SingleResponse.of(orderVendor);
    }

    /**
     * 供应商订单详情-整单接单
     *
     * @param dto
     * @return
     */
    @Path("vendorOrderTaking")
    @POST
    @Operation(summary = "供应商订单详情-整单接单", tags = CUSTOM_SERVICE, description = "ids必填")
    public SingleResponse<Boolean> vendorOrderTaking(@Parameter OrderVendorDto dto) {
        log.info("------------------------供应商订单详情-整单接单vendorConfirmOrders Param：{}------------------------", JSONObject.toJSONString(dto));
        //查询流程信息并分页
        if (CollectionUtils.isEmpty(dto.getIds())) {
            return SingleResponse.buildFailure("-1", "供应商订单ID集合必填");
        }
        boolean flag = orderService.orderTaking(dto.getIds());
        return SingleResponse.of(flag);
    }

    /**
     * 供应商订单详情-查看物流
     *
     * @param dto
     * @return
     */
    @Path("vendorLogistics")
    @POST
    @Operation(summary = "供应商订单详情-查看物流", tags = CUSTOM_SERVICE, description = "id、pageIndex、pageSize必填")
    public SingleResponse<BOList> vendorLogistics(@Parameter OrderVendorGoodsDto dto) {
        log.info("------------------------供应商订单详情-查看物流vendorLogistics Param：{}------------------------", JSONObject.toJSONString(dto));
        if (StringUtils.isBlank(dto.getId())) {
            return SingleResponse.buildFailure("-1", "供应商订单ID必填");
        }
        if (null == dto.getPageIndex() || null == dto.getPageSize()) {
            return SingleResponse.buildFailure("-1", "pageIndex、pageSize必填");
        }
        String tableName = getTableName(ModelConst.T_ORDER_TRACE);
        StringBuilder listSql = new StringBuilder();
        StringBuilder countSql = new StringBuilder();
        listSql.append("select * from " + tableName + " where deleted ='0' and order_vendor_goods_id ='" + dto.getId() + "' order by createdTime desc limit " + dto.getPageIndex() * dto.getPageSize() + ", " + dto.getPageSize());
        countSql.append("select count(*) from " + tableName + " where deleted ='0' and order_vendor_goods_id ='" + dto.getId() + "'");
        List<Map<String, Object>> resultList = jdbcTemplate.queryForList(listSql.toString(), new HashMap<>());
        int count = 0;
        try {
            count = jdbcTemplate.queryForObject(countSql.toString(), new HashMap<>(), Integer.class);
        } catch (DataAccessException e) {
            e.printStackTrace();
        }
        log.info("------------------------供应商订单详情-查看物流vendorLogistics Result：{}------------------------", JSONObject.toJSONString(resultList));
        //构建结果集
        BOList bOList = new BOList();
        bOList.setData(resultList);
        bOList.setTotal(count);
        bOList.setSchemaCode(ModelConst.T_ORDER_TRACE);
        return SingleResponse.of(bOList);
    }

    /**
     * 供应商订单详情-查看退款记录
     *
     * @param dto
     * @return
     */
    @Path("vendorRefundRecords")
    @POST
    @Operation(summary = "供应商订单详情-查看退款记录", tags = CUSTOM_SERVICE, description = "id必填")
    public SingleResponse vendorRefundRecords(@Parameter OrderVendorGoodsDto dto) {
        log.info("------------------------供应商订单详情-查看退款记录 vendorRefundRecords Param：{}------------------------", JSONObject.toJSONString(dto));
        //查询流程信息并分页
        if (StringUtils.isBlank(dto.getId())) {
            return SingleResponse.buildFailure("-1", "供应商订单ID必填");
        }
        List<Map<String, Object>> result = JdbcTemplateUtils.builder(ModelConst.T_ORDER_GOODS_RETURNS).selectField("*")
                .eq("order_vendor_goods_id", dto.getId()).sort("createdTime desc").queryForList();
        log.info("------------------------供应商订单详情-查看退款记录 applyRefundInfo Result：{}------------------------", JSONObject.toJSONString(result));
        return SingleResponse.of(!CollectionUtils.isEmpty(result) ? result.get(0).get("extends_attr") : null);
    }

    /**
     * 供应商订单详情-发货-发货物流提交
     *
     * @param dto
     * @return
     */
    @Path("vendorDeliveryLogistics")
    @POST
    @Operation(summary = "供应商订单详情-发货-发货物流提交", tags = CUSTOM_SERVICE, description = "eg:{\n" +
            "    \"logistics\": \"顺丰\",\n" +
            "    \"waybills\": [\n" +
            "        \"12345678912121\"\n" +
            "    ],\n" +
            "    \"freight\":10,\n" +
            "    \"arrivalTime\": \"2021-05-07 17:32:30\",\n" +
            "    \"orderVendorGoodsIds\": [\n" +
            "        \"af2c075e554e4956b53a66692b77f04c\"\n" +
            "    ],\n" +
            "    \"quantitys\": [10]\n" +
            "}")
    public SingleResponse<BO> vendorDeliveryLogistics(@Parameter OrderTraceDto dto) {
        log.info("------------------------供应商订单详情-发货-发货物流提交vendorDeliveryLogistics Param：{}------------------------", JSONObject.toJSONString(dto));
        return orderService.vendorDeliveryLogistics(dto);
    }

    /**
     * 供应商订单详情-修改物流
     *
     * @param dto
     * @return
     */
    @Path("vendorUpdateLogistics")
    @POST
    @Operation(summary = "供应商订单详情-修改物流", tags = CUSTOM_SERVICE, description = "id、waybill必填")
    public SingleResponse<BO> vendorUpdateLogistics(@Parameter OrderTraceDto dto) {
        log.info("------------------------供应商订单详情-修改物流vendorUpdateLogistics Param：{}------------------------", JSONObject.toJSONString(dto));
        //查询流程信息并分页
        if (StringUtils.isBlank(dto.getId())) {
            return SingleResponse.buildFailure("-1", "订单物流跟踪表ID必填");
        }
        if (StringUtils.isBlank(dto.getWaybill())) {
            return SingleResponse.buildFailure("-1", "运单号必填");
        }
        if (StringUtils.isBlank(dto.getLogistics())) {
            return SingleResponse.buildFailure("-1", "物流必填");
        }
        Map<String, Object> map = new HashMap<>();
//        map.put("type", TraceTypeEnum.ShippingLogistics.toString());
        map.put("logistics", dto.getLogistics());
        map.put("waybill", dto.getWaybill());
        map.put("id", dto.getId());
        SingleResponse<BO> bo = BoServiceUtils.updateMainBo(ModelConst.T_ORDER_TRACE, map);
        log.info("------------------------供应商订单详情-修改物流vendorUpdateLogistics Result：{}------------------------", JSONObject.toJSONString(bo));
        return bo;
    }

    /**
     * 供应商订单详情-退款审批-默认地址
     *
     * @return
     */
    @Path("defaultAddress")
    @POST
    @Operation(summary = "供应商订单详情-退款审批-默认地址", tags = CUSTOM_SERVICE)
    public SingleResponse<BO> defaultAddress() {
        Map<String, Object> address = new HashMap<>();
        List<Map<String, Object>> addressList = getAddress(RequestContext.getCorpLoginId(), true, null);
        if (!CollectionUtils.isEmpty(addressList)) {
            address = addressList.get(0);
        }
        //构建结果集
        BO bo = new BO();
        bo.setSchemaCode(ModelConst.T_MEMBER_DELIVER_ADDRESS);
        bo.setData(address);
        return SingleResponse.of(bo);
    }

    /**
     * 供应商订单详情-退款审批-确认
     *
     * @param
     * @return
     */
    @Path("vendorRefundApproval")
    @POST
    @Operation(summary = "供应商订单详情-退款审批-确认", tags = CUSTOM_SERVICE, description = "orderGoodsIds、approval必填")
    public SingleResponse vendorRefundApproval(@Parameter AgreeRefundVO agreeRefundVO) {
        if (CollectionUtils.isEmpty(agreeRefundVO.getOrderGoodsIds())) {
            return SingleResponse.buildFailure("-1", "订单商品ID集合必填");
        }
        if (null == agreeRefundVO.getApproval()) {
            return SingleResponse.buildFailure("-1", "是否同意退款必填");
        }
        log.info("------------------------供应商订单详情-退款审批-确认 vendorRefundApproval Param：{}------------------------", JSONObject.toJSONString(agreeRefundVO));
        // 退款审批-确认,供应商审批
        agreeRefundVO.setType("2");
        SingleResponse result = orderService.approvalRefund(agreeRefundVO);
        return result;
    }

    /**
     * 供应商订单详情-确认到货
     *
     * @param
     * @return
     */
    @Path("vendorConfirmDelivery")
    @POST
    @Operation(summary = "供应商订单详情-确认到货", tags = CUSTOM_SERVICE, description = "ids必填")
    public SingleResponse<BO> vendorConfirmDelivery(@Parameter OrderVendorGoodsDto dto) {
        if (CollectionUtils.isEmpty(dto.getIds())) {
            return SingleResponse.buildFailure("-1", "供应商订单商品ID集合必填");
        }
        log.info("------------------------供应商订单详情-确认到货 vendorConfirmDelivery Param：{}------------------------", JSONObject.toJSONString(dto));
        // 退款审批-确认
        return orderService.confireReturn(dto.getIds());
    }

    /**
     * 转采管理-采购订单-修改订单-通过采购订单ID查询转采订单商品数据
     *
     * @param dto
     * @return
     */
    /*@Path("purchaseGoodsFindByPurchaseId")
    @POST
    @Operation(summary = "转采管理-采购订单-修改订单-通过采购订单ID查询转采订单商品数据", tags = CUSTOM_SERVICE, description = "id必填")
    public SingleResponse<BO> purchaseGoodsFindByPurchaseId(@Parameter MemberPurchaseOrderDto dto) {
        return transferOrderService.purchaseGoodsFindByPurchase(dto);
    }*/

    /**
     * 供应商订单详情-导出发货单-导出
     *
     * @param bo
     * @return
     */
    @Path("exporDeliveryCrmGoodsReportexcel")
    @POST
    @Operation(summary = "供应商订单详情-导出发货单-导出", tags = CUSTOM_SERVICE, description = "入参:{data:{ids:[],fileType:'pdf/xlsx'}}")
    public SingleResponse exporDeliveryCrmGoodsReportexcel(TraderSaveOrUpdateBo bo) {
        List<String> ids = (List<String>) bo.getData().get("ids");
        if (ObjectUtils.isEmpty(ids)) {
            return SingleResponse.buildFailure("-1", "请求参数ids不能为空");
        }

        String fileType = (String) bo.getData().get("fileType");
        ReportType reportType = ReportType.get(fileType);

        if (reportType == null) {
            return SingleResponse.buildFailure("-1", "请求参数fileType不能为空");
        }
        String orderVendorTableName = getTableName(ModelConst.T_ORDER_VENDOR);
        String goodsTableName = getTableName(ModelConst.T_ORDER_VENDOR_GOODS);
        Map<String, Object> parameter = new HashMap<>();
        StringBuilder listSql = new StringBuilder();
        StringBuilder whereSql = new StringBuilder();
        listSql.append("select mpg.id, " +
                "mpg.*,tos.*  from " + goodsTableName + " mpg " +
                "LEFT JOIN " + orderVendorTableName + " tos on mpg.order_vendor_id = tos.id where mpg.deleted = '0' ");
        //云平台订单号
        whereSql.append(" and mpg.id in (:id) ");
        parameter.put("id", ids);
        listSql.append(whereSql);
        listSql.append(" order by mpg.createdTime desc");
        log.info("------------------------供应商订单详情-导出发货单-导出列表 exporPurchasePaymentReport listSql：{}------------------------parameter：{}", listSql, JsonUtils.toJson(parameter));
        List<Map<String, Object>> data = jdbcTemplate.queryForList(listSql.toString(), parameter);

        if (data.isEmpty()) {
            return SingleResponse.buildFailure("-1", "未获取到下载数据");
        }
        String exportField="";
        //判断是否带价格 是否带价格，1-带价格，2-不带价格
        boolean flag = Objects.equals(bo.getIsWithPrice(), "1");
        if (flag){
            exportField = "{\"vendorOrderId\":\"order_vendor_id\",\"fullName\":\"organization_name\",\"mobile\":\"phone\",\"address\":\"address\",\"goodsId\":\"goods_id\",\"brand\":\"brand\",\"name\":\"name\",\"spec\":\"spec\",\"unit\":\"unit\",\"customerOrderId\":\"order_customer_id\",\"num\":\"num\",\"companyName\":\"organization_name\",\"erp\":\"erp_po\",\"sku\":\"sku\",\"memo\":\"memo\",\"description\":\"description\",\"price\":\"price\",\"model\":\"model\",\"customerOrderTime\":\"place_order_time\",\"amount\":\"amount\",\"platformName\":\"data_sources\",\"platformId\":\"platform_id\"}";
        }else {
            exportField = "{\"vendorOrderId\":\"order_vendor_id\",\"fullName\":\"organization_name\",\"mobile\":\"phone\",\"address\":\"address\",\"goodsId\":\"goods_id\",\"brand\":\"brand\",\"name\":\"name\",\"spec\":\"spec\",\"unit\":\"unit\",\"customerOrderId\":\"order_customer_id\",\"num\":\"num\",\"companyName\":\"organization_name\",\"erp\":\"erp_po\",\"sku\":\"sku\",\"memo\":\"memo\",\"description\":\"description\",\"price\":\"price\",\"model\":\"model\",\"customerOrderTime\":\"place_order_time\",\"platformName\":\"data_sources\"}";
        }
        JSONObject exportJson = JSON.parseObject(exportField);
        List<Map<String, Object>> fileData = data.stream().map(m -> {
            Map<String, Object> mf = new HashMap<>();
            for (String key : exportJson.keySet()) {
                mf.put(key, m.get(exportJson.get(key)));
                //z转换时间格式
                if ("customerOrderTime".equals(key)){
                    Date date=(Date)m.get(exportJson.get(key));
                    mf.put(key, DateUtil.format(date, DatePattern.NORM_DATETIME_PATTERN));
                }
            }
            return mf;
        }).collect(Collectors.toList());


        if (log.isDebugEnabled()) {
            log.debug("======================供应商订单详情-导出发货单-导出参数:reportType={},fileData={}", reportType.getId(), JSON.toJSONString(fileData));
        }
        if (flag){
            ReportUtils.exportReport("order/delivery_crm_goods_price_report.jrxml", reportType.getId(), fileData);
        }else {
            ReportUtils.exportReport("order/delivery_crm_goods_reportexcel.jrxml", reportType.getId(), fileData);
        }

        return SingleResponse.buildSuccess();
    }

    /**
     * 供应商订单详情-导出采购订单-导出
     *
     * @param bo
     * @return
     */
    @Path("exporVendorOrderContractNoSealReport")
    @POST
    @Operation(summary = "供应商订单详情-导出采购订单-导出", tags = CUSTOM_SERVICE, description = "入参:{data:{ids:[],fileType:'pdf/xlsx'}}")
    public SingleResponse exporVendorOrderContractNoSealReport(SaveOrUpdateBO bo) {
        List<String> ids = (List<String>) bo.getData().get("ids");
        if (ObjectUtils.isEmpty(ids)) {
            return SingleResponse.buildFailure("-1", "请求参数ids不能为空");
        }

        String fileType = (String) bo.getData().get("fileType");
        ReportType reportType = ReportType.get(fileType);

        if (reportType == null) {
            return SingleResponse.buildFailure("-1", "请求参数fileType不能为空");
        }

        String mpgTableName = getTableName(ModelConst.T_ORDER_VENDOR);
        String mpoTableName = getTableName(ModelConst.T_ORDER_VENDOR_GOODS);
        Map<String, Object> parameter = new HashMap<>();
        StringBuilder listSql = new StringBuilder();
        StringBuilder whereSql = new StringBuilder();
        listSql.append("select mpg.id, " +
                "mpg.*,tos.* ,org.email,org.connect from " + mpgTableName + " mpg " +
                "LEFT JOIN " + mpoTableName + " tos on mpg.id = tos.order_vendor_id " +
                "left join systemmanagement.i_systemmanagement_t_organization org on mpg.organization_id = org.id where mpg.deleted = '0' ");
        //云平台订单号
        whereSql.append(" and mpg.id in (:id) ");
        parameter.put("id", ids);
        listSql.append(whereSql);
        listSql.append(" order by mpg.createdTime desc");
        log.info("------------------------供应商订单详情-导出发货单-导出列表 exporPurchasePaymentReport listSql：{}------------------------parameter：{}", listSql, JsonUtils.toJson(parameter));
        List<Map<String, Object>> data = jdbcTemplate.queryForList(listSql.toString(), parameter);

        if (data.isEmpty()) {
            return SingleResponse.buildFailure("-1", "未获取到下载数据");
        }

        String exportField = "{\"customerOrderId\":\"order_customer_id\",\"address\":\"address\",\"id\":\"id\",\"vendorOrderId\":\"order_vendor_id\",\"brand\":\"brand\",\"name\":\"name\",\"model\":\"model\",\"unit\":\"unit\",\"amount\":\"amount\",\"time\":\"createdTime\",\"vendorName\":\"vendor_organization_name\",\"price\":\"price\",\"num\":\"quantity\",\"description\":\"description\",\"delivery\":\"delivery\",\"vendorOrderAmount\":\"amount\",\"expectedTime\":\"delivery_time\",\"mobile\":\"phone\",\"orderMemberName\":\"place_order_fullname\",\"email\":\"email\",\"platformName\":\"data_sources\"}";
        JSONObject exportJson = JSON.parseObject(exportField);
        List<Map<String, Object>> fileData = data.stream().map(m -> {
            Map<String, Object> mf = new HashMap<>();
            for (String key : exportJson.keySet()) {
                mf.put(exportJson.getString(key), m.get(key));
            }
            return mf;
        }).collect(Collectors.toList());


        if (log.isDebugEnabled()) {
            log.debug("======================供应商订单详情-导出采购订单-导出参数:reportType={},fileData={}", reportType.getId(), JSON.toJSONString(fileData));
        }
        ReportUtils.exportReport("order/vendor_order_contract_no_seal_report.jrxml", reportType.getId(), fileData);

        return SingleResponse.buildSuccess();
    }
}
